<?php

use Biz\model\activity\Kohler;
use Biz\service\brand\Brand;
use Doraemon\service\Format\Note\HandleNote;
use Doraemon\service\statSign\Basic as statSign;
use Doraemon\tools\BlockType;
use hhz\constant\redis\redisKeys;
use Hhz\Redis\newCache;

class KohlerAction extends ActionPlugin
{
    const USER_LEVEL = self::LEVEL_NOTHING;

    public function main()
    {
        $day = $this->getRequest()->getQuery('day', '');
        $day = $day ?: date('Ymd');
        if ($day >= 20230426) {
            $day = 20230426;
        }
        $list = Kohler::getDayList($day);
        foreach ($list as $row) {
            $videoList[] = [
                'id' => $row['id'],
                'video_id' => $row['video_id'],
                'tab_img' => $row['tab_img_url'],
                'poster_url' => $row['poster_url'],
                'video_url' => $row['video_play_url']
            ];
        }
        $brandId = 275;
        $brandList = Brand::getBrandUserInfos([$brandId], true, false, true);
        $brandInfo = $brandList[$brandId];
        $subKeyPrefix = 'kohler20230420-' . $this->uid;
        $redis = new newCache(redisKeys::KEY_B_CACHE_ACTIVITY_SUBSCRIBE);
        $sub = $redis->getCache($subKeyPrefix);
        $blankId = '00051gl05003mf0h';
        $noteId = '00634o500000fgj1';
        $data = [
            'video_list' => $videoList,
            'note_list' => $this->getNotes(),
            'brand_info' => $brandInfo,
            'blank' => [
                'id' => $blankId,
                'statSign' => statSign::genStatSign(statSign::MODULE_KOHLER_PAGE_BLANK, [
                    statSign::EXTEND_KEY_OBJ_ID => $blankId,
                    statSign::EXTEND_KEY_OBJ_TYPE => BlockType::TYPE_BLANK,
                ])
            ],
            'note' => [
                'id' => $noteId,
                'statSign' => statSign::genStatSign(statSign::MODULE_KOHLER_PAGE_NOTE, [
                    statSign::EXTEND_KEY_OBJ_ID => $noteId,
                    statSign::EXTEND_KEY_OBJ_TYPE => BlockType::TYPE_PHOTO,
                ])
            ],
            'is_sub' => $sub ?? 0,
        ];
        $this->setSuccess($data);
    }

    private function getNotes()
    {
        $result = [];
        $noteIds = ['0061efc000000sg7', '00621ie00000vnzr', '0062cn5000003as9', '0062uhm000000sg7', '006331s000000sg7', '00639sf000000sg7', '00665wv00000e7pr'];
        $noteList = HandleNote::handleNote($noteIds, HandleNote::BASE_INFO);
        foreach ($noteIds as $noteId) {
            if (isset($noteList[$noteId]) && $noteList[$noteId]) {
                $noteList[$noteId]['statSign'] = statSign::genStatSign(statSign::MODULE_KOHLER_PAGE_NOTE, [
                    statSign::EXTEND_KEY_OBJ_ID => $noteId,
                    statSign::EXTEND_KEY_OBJ_TYPE => BlockType::TYPE_PHOTO,
                ]);
                $result[] = $noteList[$noteId];
            }
        }
        return $result;
    }
}